//
//  DCTabBarViewController.m
//  Driver
//
//  Created by 大橙子 on 2018/11/5.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCTabBarViewController.h"
#import "DCNavigationViewController.h"
#import "DCTaskViewController.h"
#import "DCMarketViewController.h"
#import "DCTransportViewController.h"
#import "DCMineViewController.h"
@interface DCTabBarViewController ()

@end

@implementation DCTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (iOS7) {
        self.tabBar.translucent = NO;
    }
    /* 设置所UITabBarItem的文字属性*/
    UITabBarItem *item = [UITabBarItem appearance];
    //普通状态下的文字属性
    NSMutableDictionary *norDic = [NSMutableDictionary dictionary];
    norDic[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    norDic[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    [item setTitleTextAttributes:norDic forState:UIControlStateNormal];
    //选中状态下的文字属性
    NSMutableDictionary *selectedDic = [NSMutableDictionary dictionary];
    selectedDic[NSForegroundColorAttributeName] = BlueColor;
    [item setTitleTextAttributes:selectedDic forState:UIControlStateSelected];
    
    /** 添加子控制器*/
    [self setUpOneChildViewController:[[DCTaskViewController alloc] init] title:@"任务" image:@"task" selectedImg:@"task-selected"];
    [self setUpOneChildViewController:[[DCMarketViewController alloc] init] title:@"交易市场" image:@"market" selectedImg:@"market-selected"];
    [self setUpOneChildViewController:[[DCTransportViewController alloc] init] title:@"运力管理" image:@"track" selectedImg:@"track-selected"];
    [self setUpOneChildViewController:[[DCMineViewController alloc] init] title:@"个人中心" image:@"mine" selectedImg:@"mine-selected"];
    
    //解决tabbar从二级页面返回跳动问题
    [[UITabBar appearance] setTranslucent:NO];
}
-(void)setUpOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImg:(NSString *)selectedImg
{
    vc.title = title;
    vc.tabBarItem.title = title;
    UIImage *selImage = [UIImage imageNamed:selectedImg];
    if (iOS7) {
        selImage = [selImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    if (image.length) {
        vc.tabBarItem.image = [UIImage imageNamed:image];
        vc.tabBarItem.selectedImage = selImage;
    }
    DCNavigationViewController *nav = [[DCNavigationViewController alloc]initWithRootViewController:vc];
    [self addChildViewController:nav];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
